import 'result_model.dart';

///认证图形验证码:响应
class AuthCaptchaRes extends BaseModelRes {
  final String key, base64;

  AuthCaptchaRes({
    required super.retCode,
    required super.retMessage,
    required this.key,
    required this.base64,
  });

  factory AuthCaptchaRes.fromResult(final ResultModelRes res) {
    final map = res.toMap;
    return AuthCaptchaRes(
      retCode: res.retCode,
      retMessage: res.retMessage,
      key: map['key'] ?? '',
      base64: map['b64s'] ?? '',
    );
  }
}

///认证-登录请求
class AuthLoginReq {
  final String tenantCode, account, passwd, sn, key, code;

  const AuthLoginReq({
    required this.tenantCode,
    required this.account,
    required this.passwd,
    required this.sn,
    required this.key,
    required this.code,
  });

  Map<String, dynamic> toMap() => {
        'account': account,
        'passwd': passwd,
        'sn': sn,
        'key': key,
        'code': code,
      };
}

///认证-登录响应
class AuthLoginRes extends BaseModelRes {
  final String tenantId, accessToken, refreshToken, nick, avatar;

  const AuthLoginRes({
    required super.retCode,
    required super.retMessage,
    required this.tenantId,
    required this.accessToken,
    required this.refreshToken,
    required this.nick,
    required this.avatar,
  });

  factory AuthLoginRes.fromResult(final ResultModelRes res) {
    final map = res.toMap;
    return AuthLoginRes(
      retCode: res.retCode,
      retMessage: res.retMessage,
      tenantId: map['tenantId'] ?? '',
      accessToken: map['accessToken'] ?? '',
      refreshToken: map['refreshToken'] ?? '',
      nick: map['nick'] ?? '',
      avatar: map['avatar'] ?? '',
    );
  }
}

///认证-刷新令牌请求
class RefreshTokenReq {
  final String refreshToken;

  const RefreshTokenReq({required this.refreshToken});

  Map<String, dynamic> toMap() => {'refreshToken': refreshToken};
}

///认证-刷新令牌响应
class RefreshTokenRes extends BaseModelRes {
  final String accessToken, refreshToken;

  const RefreshTokenRes({
    required super.retCode,
    required super.retMessage,
    required this.accessToken,
    required this.refreshToken,
  });

  factory RefreshTokenRes.fromResult(final ResultModelRes res) {
    final map = res.toMap;
    return RefreshTokenRes(
      retCode: res.retCode,
      retMessage: res.retMessage,
      accessToken: map['accessToken'] ?? '',
      refreshToken: map['refreshToken'] ?? '',
    );
  }
}

///认证-修改密码请求
class ModifyPasswdReq {
  final String oldPasswd, newPasswd;

  const ModifyPasswdReq({
    required this.oldPasswd,
    required this.newPasswd,
  });

  Map<String, dynamic> toMap() => {
        'oldPasswd': oldPasswd,
        'newPasswd': newPasswd,
      };
}

///发送短信验证码请求
class AuthSendSmsReq {
  final String tenantCode, mobile, smsType, captchaKey, captchaCode;

  const AuthSendSmsReq({
    required this.tenantCode,
    required this.mobile,
    required this.smsType,
    required this.captchaKey,
    required this.captchaCode,
  });

  Map<String, dynamic> toMap() => {
        'mobile': mobile,
        'smsType': smsType,
        'captchaKey': captchaKey,
        'captchaCode': captchaCode,
      };
}

///忘记密码请求
class AuthForgotPasswdReq {
  final String mobile, newPasswd, smsCode;

  const AuthForgotPasswdReq({
    required this.mobile,
    required this.newPasswd,
    required this.smsCode,
  });

  Map<String, dynamic> toMap() => {
        'mobile': mobile,
        'newPasswd': newPasswd,
        'smsCode': smsCode,
      };
}
